package com.ruoyi.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.app.domain.AppOrganization;
import com.ruoyi.app.service.IAppOrganizationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组织Controller
 * 
 * @author ruoyi
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/app/organization")
public class AppOrganizationController extends BaseController
{
    @Autowired
    private IAppOrganizationService appOrganizationService;

    /**
     * 查询组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:organization:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppOrganization appOrganization)
    {
        startPage();
        List<AppOrganization> list = appOrganizationService.selectAppOrganizationList(appOrganization);
        return getDataTable(list);
    }

    /**
     * 导出组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:organization:export')")
    @Log(title = "组织", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppOrganization appOrganization)
    {
        List<AppOrganization> list = appOrganizationService.selectAppOrganizationList(appOrganization);
        ExcelUtil<AppOrganization> util = new ExcelUtil<AppOrganization>(AppOrganization.class);
        util.exportExcel(response, list, "组织数据");
    }

    /**
     * 获取组织详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:organization:query')")
    @GetMapping(value = "/{organizationId}")
    public AjaxResult getInfo(@PathVariable("organizationId") Long organizationId)
    {
        return success(appOrganizationService.selectAppOrganizationByOrganizationId(organizationId));
    }

    /**
     * 新增组织
     */
    @PreAuthorize("@ss.hasPermi('system:organization:add')")
    @Log(title = "组织", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppOrganization appOrganization)
    {
        return toAjax(appOrganizationService.insertAppOrganization(appOrganization));
    }

    /**
     * 修改组织
     */
    @PreAuthorize("@ss.hasPermi('system:organization:edit')")
    @Log(title = "组织", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppOrganization appOrganization)
    {
        return toAjax(appOrganizationService.updateAppOrganization(appOrganization));
    }

    /**
     * 删除组织
     */
    @PreAuthorize("@ss.hasPermi('system:organization:remove')")
    @Log(title = "组织", businessType = BusinessType.DELETE)
	@DeleteMapping("/{organizationIds}")
    public AjaxResult remove(@PathVariable Long[] organizationIds)
    {
        return toAjax(appOrganizationService.deleteAppOrganizationByOrganizationIds(organizationIds));
    }
}
